Skip to content

Keep things in the level with SolidCollision, not layer 30 - #70

Merged
inemtsev merged 2 commits into
mainfrom
physics-solid-collision
Nov 29, 2026
Merged

inemtsev merged 2 commits into
mainfrom
physics-solid-collision

Conversation

@inemtsev

Copy link
Copy Markdown
Owner

Resolves #67.

The level sat on PhysicsLayers.SOLIDS (layer 30), and checkLayers rejected layers 30 and 31. A game therefore had 30 of the 32 layers it shares with klyph.collision, and a mask that left out bit 30 dropped a body through the floor. Now every rigid body, soft body and particle has a SolidCollision. It is COLLIDE by default, and PASS lets the thing fall through the grid and its moving solids, bullets included. All 32 layers belong to the game. Body-to-body filtering is unchanged.

ParticleCollision { SOLIDS, EVERYTHING } is now BodyCollision { PASS, COLLIDE }, because it no longer has anything to do with solids. The CollisionLayers and PhysicsLayers KDoc and docs/physics* state both rules: Collisions needs one side's mask to match, physics needs both.

API changes (unreleased module)

  • enum class SolidCollision { COLLIDE, PASS }
  • RigidBodies / SoftBodies / Particles: setSolidCollision(handle, SolidCollision), solidCollisionOf(handle)
  • ParticleCollision → BodyCollision, collision = → bodyCollision = on Particles.add, rope, chain, strand, cloth; collisionOf → bodyCollisionOf
  • Removed PhysicsLayers.SOLIDS

Verification

./gradlew check passes, and so do the games/physics scene tests (-Pklyph.physics.sceneTests=1). The new tests are in FiltersTest. benchmarkPhysics, release build on an M4 Max, ms per step:

scene main branch
sand 5.2 5.2
soft 1.16 1.16
everything 17 17
boxes, 1,200 steps 6.81 6.68

A 600-step boxes run reads about 0.6 ms slower on the branch. The gap is gone at 150 steps, turns into a win at 1,200, and the profiles match.

API style checklist

  • Members hold only the core concept; derived operations are extensions.
  • Every new name uses the vocabulary table, or the table was extended.
  • No Boolean behavior flags, lambda is last, defaults over overloads.
  • Signatures use read-only collections, no arrays, no data class, no platform types.
  • Value classes for identifiers and units; sealed types for closed sets.
  • require/check for validation; exception types and messages follow section 5.
  • Throwing functions have an OrNull sibling where failure is expected.
  • infix/operator/property use passes section 6.
  • KDoc on every public declaration, verb-first, @throws for each exception.
  • @sample present and runs as a test.
  • toString on every stateful public type.

@pererikbergman pererikbergman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. It does what #67 asked, and the implementation points from the issue thread are in:

  • The particle flag is a bit in Particles.flags, and Solids.collide only reads it once anyPassSolids is set, so default scenes cost what they did.
  • PASS covers the grid and the moving solids, in Solids.collide, RigidContacts.findAgainstSolids and both bullet sweeps.
  • RigidBodies.setPassesSolids returns early when nothing changes and wakes the body in both directions, and both cases have tests.
  • Reused slots start clean (Particles.add overwrites flags, addAt clears passesSolids, grow() copies it).
  • SoftBodies.setSolidCollision covers the ring and the core, and the getter reads the core.

A few points, none blocking:

  1. NONE doesn't match the issue. #67's "Done when" says setLayers accepts CollisionLayers.NONE as layers, but checkLayers still rejects it, and layersAreOneOrMoreOfAllThirtyTwo makes that deliberate. Rejecting it is defensible, since under the both-sides rule layers = NONE does the same as mask = NONE. Could you say so in the PR description or update the issue, so #67 doesn't close with that line unmet?
  2. Nit: the two settings are set in different places. bodyCollision is only a parameter of add (no setter), while solidCollision is only a setter (no parameter on add). A solidCollision = parameter on add, rope and cloth would let a ghost spark be created in one call.
  3. Nit: strands and cloth have no setSolidCollision. Letting a rope or a cloth fall through the level means looping over its particles. That could be a follow-up.
  4. Nit: BodyCollision is a slightly misleading name. It also controls particle-to-particle (grain) collisions, and it reads like a property of a body rather than of a particle. The KDoc explains it, so this is fine to keep.
  5. A soft-body test would help. Only the SoftBodySamples.setSolidCollision sample covers SoftBodies.setSolidCollision. A FiltersTest case with a soft body set to PASS falling through the floor would be worth adding.

CI: the push-triggered Linux run failed after 11 seconds, before any tests ran, because Gradle couldn't download com.vanniktech.maven.publish 0.37.0. The pull_request run passed on all three platforms, so a re-run should clear it.

@inemtsev

inemtsev commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner Author

Thanks. Fixed in 03d54a5:

  1. setLayers now accepts NONE, as the issue says and as a klyph Collider does. A thing on no layer collides with no other thing and still stands on the floor; aBodyOnNoLayerPassesOtherBodiesAndStandsOnTheFloor checks both for a rigid body and a soft body. The @throws lines are gone.
  2. Leaving it as is: setSolidCollision sits with setLayers, setMotion and setResponse, the other settings changed after a thing is made.
  3. A follow-up if anyone asks; rope.particles.forEach { world.particles.setSolidCollision(it, SolidCollision.PASS) } covers it today.
  4. Keeping the name for now.
  5. passingSolidsThingsFallThroughTheLevel already had a soft body set to PASS. I added aSoftBodySetBackToCollideLandsOnTheFloor for the way back.

The physics level sat on PhysicsLayers.SOLIDS, layer 30, and checkLayers
rejected layers 30 and 31, so a game lost two of the 32 layers it shares
with klyph.collision. Each rigid body, soft body and particle now has a
SolidCollision (COLLIDE by default, PASS falls through the level), set
with setSolidCollision, and every layer is the game's own.
ParticleCollision { SOLIDS, EVERYTHING } becomes BodyCollision
{ PASS, COLLIDE }, since it no longer says anything about solids.

The CollisionLayers and PhysicsLayers KDoc and the physics docs state
both layer rules: either side for Collisions, both sides for physics.

Resolves #67.
…OLLIDE

#67 asks for setLayers to accept NONE, as a klyph Collider does. Under
the both-sides rule a thing on no layer collides with no other thing,
and the level still holds it, so the check had nothing left to guard.
@inemtsev
inemtsev force-pushed the physics-solid-collision branch from 03d54a5 to 9b3c825 Compare November 28, 2026 12:12
@inemtsev
inemtsev merged commit 330dbf1 into main Nov 29, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Take the level out of the physics collision layers

2 participants